<template>
	<div class="page-hero" v-if="model">	<!-- model存在再显示下面内容，先获取数据，再显示，避免渲染早于获取数据，把异步操作变成同步操作 -->
		<div class="topbar bg-black py-2 px-3 d-flex ai-center text-white">
			<img src="../assets/logo.png" height="30">
			<div class="px-2 flex-1">
        <span class="text-white">王者荣耀</span>
        <span class="ml-2">攻略站</span>
      </div>
			<router-link to="/" tag="div">更多英雄 &gt;</router-link>
		</div>
		<div class="top" v-bind:style="{'background-image':`url(${model.banner})`}">
			<div class="info text-white p-3 h-100 d-flex flex-column jc-end">
				<div class="fs-sm">{{model.title}}</div>
				<div class="my-2">{{model.name}}</div>
				<div class="fs-sm">{{model.categories.map(v=>v.name).join('/')}}</div>   <!--里面有name属性，看server/routes/web/index.js的populate('categories')。展开一个json对象,得到['a','b'],然后用/分隔开,变成'a/b'-->
				<div class="d-flex jc-between pt-2">
					<div class="scores d-flex ai-center" v-if="model.scores">	<!-- model.scores属性存在即显示以下内容 -->
						<span>难度</span>
            <span class="badge bg-primary">{{model.scores.difficulty}}</span>
            <span>技能</span>
            <span class="badge bg-blue-1">{{model.scores.skills}}</span>
            <span>攻击</span>
            <span class="badge bg-danger">{{model.scores.attack}}</span>
            <span>生存</span>
            <span class="badge bg-dark">{{model.scores.survive}}</span>
					</div>
					<router-link to="/" tag="span" class="text-grey fs-sm">
            皮肤: 2 &gt;
          </router-link>
				</div>
			</div>
		</div>
	</div>
</template>

<script>
export default {
	props: {
		id: { required: true }
	},
	data() {
    return {
      model: null	//定义model为null，null会转换为false，只有变成数组等采薇true
    }
	},
	methods: {
    async fetch() {
      const res = await this.$http.get(`heroes/${this.id}`)
      this.model = res.data
    }
	},
	created() {
    this.fetch()
  }
}
</script>>

<style lang='scss'>
.page-hero {
	.top {
		height: 50vw;
		background: #fff no-repeat top center;
		background-size: auto 100%;
	}
	.info {
		background: linear-gradient(rgba(0,0,0,0), rgba(0,0,0,1));//从上到下颜色逐渐变化
		.scores
			.badge {
				margin: 0 0.25rem;
        display: inline-block;
        width: 1rem;
        height: 1rem;
        line-height: 0.9rem;
        text-align: center;
        border-radius: 50%;
        font-size: 0.6rem;
        border: 1px solid rgba(255,255,255,0.2);
			}
	}
}

</style>>